package edu.xhu.communityantiepidemicsystemback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.xhu.communityantiepidemicsystemback.dto.*;
import edu.xhu.communityantiepidemicsystemback.entity.Staff;
import edu.xhu.communityantiepidemicsystemback.mapper.StaffMapper;
import edu.xhu.communityantiepidemicsystemback.service.IStaffService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcx
 * @since 2022-06-20
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements IStaffService {

//分页查询
    @Override
    public IPage<Staff> selectStaffList(Query query) {

        Page<Staff> page=new Page<>();
        page.setCurrent(query.getPageNO());
        page.setSize(query.getPageSize());
        return this.page(page);
    }
    //模糊查询
    @Override
    public IPage<Staff> fuzzyStaffInfo(Fuzzy fuzzy) {
        Page<Staff> page=new Page<>();
        page.setCurrent(fuzzy.getPageNO());
        page.setSize(fuzzy.getPageSize());
        QueryWrapper<Staff> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(fuzzy.getSelect(), fuzzy.getSearchStr());
        return this.page(page,queryWrapper);
    }
    //增加
    @Override
    public boolean addStaff(CreatStaff creatStaff) {
        Staff staff=new Staff();
        BeanUtils.copyProperties(creatStaff,staff);
        staff.setCreateTime(LocalDateTime.now());
        staff.setCreator("system");
        return this.save(staff);
    }

    @Override
    public boolean delStaff(Integer id) {
        return this.removeById(id);
    }

    @Override
    public boolean updateStaff(UpdateStaff updateStaff) {
        Staff staff=new Staff();
        BeanUtils.copyProperties(updateStaff,staff);
        staff.setUpdateTime(LocalDateTime.now());
        staff.setOperator("system");
        return this.updateById(staff);

    }
}
